using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using Bosphorus.Integration.Jira.Thor.Client.PlugIn.Core.Forms;
using Bosphorus.Integration.Jira.Thor.Client.PlugIn.Core.PlugIn;
using Bosphorus.Integration.Jira.Thor.Client.PlugIn.JiraIntegrationService;
using Bosphorus.Integration.Jira.Thor.Client.PlugIn.Resource.String;
using Bosphorus.Integration.Jira.Thor.Client.PlugIn.View.Domain;

namespace Bosphorus.Integration.Jira.Thor.Client.PlugIn.Implementation
{
    public class SvnPlugIn : AbstractPlugIn
    {
        private string currentComment;

        public override void Initialize()
        {
            base.Initialize();
            base.OnCommitFinished += new EventHandler<CommitFinishedEventArgs>(OnCommitFinished);
        }

        public void OnCommitFinished(object sender, CommitFinishedEventArgs e)
        {
            
        }

        public override bool Validate(string parameters)
        {
            return !string.IsNullOrEmpty(parameters);
        }

        public override string GetCommitMessage(string parameters, string originalMessage)
        {
            Issues issues = new Issues(parameters);
            currentComment = originalMessage;
            issues.OkClicked += new EventHandler<OkClickedEventArgs>(OnOkClicked);
            issues.ShowDialog();

            return currentComment;
        }

        private void OnOkClicked(object sender, OkClickedEventArgs e)
        {
            foreach (IssueViewModel issue in e.ClosedIssue)
            {
                if (!issue.IsSelected)
                {
                    continue;
                }
                currentComment += string.Format(Message.CLOSE_ISSUE_MESSAGE_FORMAT, issue.Key, issue.Assignee);
            }
        }
    }
}